/**
  ******************************************************************************
  * @file 	
  * @brief
  ******************************************************************************
  */

#ifndef __ZBCOMM_H
#define __ZBCOMM_H

#include "main.h"


// defines
//#ifdef  
#define bufferSize 		256		// size of the buffer of data we tx/rx
#define lineframevalid 	0x300 		// pins 8 and 9 set meaning frame and line valid
#define maxPackets		5			// max amount of packets we can have at a time, this is its own buffer X*(packetsize+overhead)
//#define packetSize 		1024	// size of one packet payload, no header
#define overhead 		16			// besides the actual data how much do we have in a packet ? 

extern pktHdr txHdr;
extern dmaPush dmaTX;
extern CircularBuffer rxUSCBuff;


 

/*
  PACKET DEFINITION 
	see protocol.h or zbcontrol.h
*/
// basic comm
void initComm(void);
void USART2_Config(void);		// config of usart2 which is the serial line

// circular buffer stuff
void cbInit(CircularBuffer *cb);
int cbCount(CircularBuffer *cb);
 
int cbIsFull(CircularBuffer *cb);
 
int cbIsEmpty(CircularBuffer *cb);
 
/* Write an element, overwriting oldest element if buffer is full. App can
   choose to avoid the overwrite by checking cbIsFull(). */
void cbWrite(CircularBuffer *cb, u8 *elem);
 
/* Read oldest element. App must ensure !cbIsEmpty() first. */
void cbRead(CircularBuffer *cb, u8 *elem);

// usart
void DMA_TXPacket(u8 *packet, int len); // sends a packet out prepending header to beggining and using mem->usart dma
void DMA_TXPush(void);
void BASIC_TXPush(void); // sends out blocking
void DMA_RXPacket(u8 *packet, int len);

// wireless
void rfTX_Data(CircularBuffer *cb);
void Wireless_Received(unsigned char *pbuf, int len); // delegate from zbnrf driver

void testComm(void);


#endif
